package com.wcll.www;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
public class ShowSortBean {
		private int id;
		private String name;
		private int pages;
		private final int PAGE_ROWS = 20;
		private static Connection con=null;
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getPages() {
			return pages;
		}
		public void setPages(int pages) {
			this.pages = pages;
		}
		public int getPAGE_ROWS() {
			return PAGE_ROWS;
		}
		public static Connection getCon() throws ClassNotFoundException, SQLException {
			if(con==null){
				Class.forName("com.mysql.jdbc.Driver");
				con = DriverManager.getConnection("jdbc:mysql://localhost/jobs?useUnicode=true&characterEncoding=UTF8","root","");
			}
			return con;
		}
		public static void setCon(Connection con) {
			ShowSortBean.con = con;
		}
		public ArrayList<ShowSortBean> showSort(int currage){
			ArrayList<ShowSortBean> hm = new ArrayList<ShowSortBean>();
			int n = (currage-1)*this.PAGE_ROWS;
			try{
			con = ShowSortBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select id,ja_name from job_assort order by id desc limit "+n+","+this.PAGE_ROWS);
			while(rs.next()){
				ShowSortBean ss = new ShowSortBean();
				ss.setId(rs.getInt("id"));
				ss.setName(rs.getString("ja_name"));
				hm.add(ss);
				}
			rs.close();
			st.close();
			}catch(Exception e){}
			return hm;	
			}
		public ArrayList<ShowSortBean> showJobSort(String s,int currage){
			ArrayList<ShowSortBean> al = new ArrayList<ShowSortBean>();
			int n = (currage-1)*this.PAGE_ROWS;
			try{
				con = ShowSortBean.getCon();
				Statement st = con.createStatement();
				ResultSet rs = st.executeQuery("select id,jaa_name from job_assort_avatar where ja_id='"+s+"'"+" order by id desc limit "+n+","+this.PAGE_ROWS);
				while(rs.next()){
					ShowSortBean ss = new ShowSortBean();
					ss.setId(rs.getInt("id"));
					ss.setName(rs.getString("jaa_name"));
					al.add(ss);
				}
				rs.close();
				st.close();
			}catch(Exception e){};
			return al;
		}
		public boolean deleJaa(int id){
			boolean flags = false;
			try{
				con = ShowSortBean.getCon();
				Statement st = con.createStatement();
				st.execute("delete from job_assort_avatar where id="+id);
				if(st.getUpdateCount()==1){
					flags = true;
				}
		}catch(Exception e){}
			return flags;
	}
		public boolean modifyJaa(int id,String s){
			boolean flags = false;
			try{
				con = ShowSortBean.getCon();
				Statement st = con.createStatement();
				st.execute("update  job_assort_avatar set jaa_name= '"+s+"' where id="+id);
				if(st.getUpdateCount()==1){
					flags = true;
				}
		}catch(Exception e){}
			return flags;
	}
	public int getCounts(String s){
		int pages = 0;
		double totals;
		
		try{
			con = ShowSortBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery(s);
			while(rs.next()){
				totals = (double)rs.getInt("a");
				pages = (int)Math.ceil(totals/this.PAGE_ROWS);
			}
		}catch(Exception e){}
		return pages;
	}
}
